<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/admin/base/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>核心业务管理</el-breadcrumb-item>
      <el-breadcrumb-item>车位收费管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>



  <el-container>
    <el-header>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="车位号码">
          <el-input v-model="formInline.carId"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
        <el-form-item label="缴费状态">
          <el-select v-model="formInline.chargeState">
            <el-option label="已缴费" value='1'></el-option>
            <el-option label="未缴费" value='0'></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="Submit">筛选</el-button>
        </el-form-item>
      </el-form>
    </el-header>
    <el-main>
      <el-button type="primary" @click="dialogFormVisible = true">添加</el-button>
      <el-button type="warning" @click="deletes()">删除</el-button>
      <el-tooltip content="刷新" placement="bottom">
        <el-button icon="el-icon-refresh-left" style="margin: 0 0 0 10px" @click="reFresh()"></el-button>
      </el-tooltip>
      <el-dialog title="添加车位用户" :visible.sync="dialogFormVisible">
        <el-form :model="car">
          <el-form-item label="车牌" :label-width="formLabelWidth">
            <el-input v-model="car.carId" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="车主" :label-width="formLabelWidth">
            <el-input v-model="car.chargePerson" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="是否缴费" :label-width="formLabelWidth">
            <el-select v-model="car.chargeState">
              <el-option label="已缴费" value='1'></el-option>
              <el-option label="无缴费" value='0'></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="缴费时间" :label-width="formLabelWidth">
            <el-input v-model="car.chargeDate" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="到期时间" :label-width="formLabelWidth">
            <el-input v-model="car.arrivedDate" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="缴费金额" :label-width="formLabelWidth">
            <el-input v-model="car.money" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="备注" :label-width="formLabelWidth">
            <el-input v-model="car.remark" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item :label-width="formLabelWidth" style="width:350px;display:block;margin: 0 auto">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="add()">确 定</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
      <el-table
          :data="carChargeArr"
          style="width: 100%"
          ref="multipleTable"
          tooltip-effect="dark"
          @selection-change="handleSelectionChange"
          height="250"
          border>
        <el-table-column
            type="selection"
            width="55">
        </el-table-column>
        <el-table-column
            prop="carId"
            label="车位号"
            width="80">
        </el-table-column>
        <el-table-column
            prop="chargePerson"
            label="车主"
            width="80">
        </el-table-column>
        <el-table-column
            prop="chargeDate"
            label="缴费时间">
        </el-table-column>
        <el-table-column
            prop="arrivedDate"
            label="结束时间">
        </el-table-column>
        <el-table-column
            prop="money"
            label="金额">
        </el-table-column>
        <el-table-column
            prop="chargeState"
            label="状态">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.chargeState==1">已缴费</el-tag>
            <el-tag type="danger" v-else>无缴费</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
                size="mini"
                @click="dialogFormVisible1 = true">缴费</el-button>
            <el-button
                size="mini"
                type="danger"
                @click="deleteRow(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
        <el-table-column
            prop="remark"
            label="备注">
        </el-table-column>
      </el-table>
      <el-dialog title="缴费" :visible.sync="dialogFormVisible1">
        <el-form :model="car">
          <el-form-item label="车牌" :label-width="formLabelWidth">
            <el-input v-model="car.carId" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="是否缴费" :label-width="formLabelWidth">
            <el-select v-model="car.chargeState">
              <el-option label="已缴费" value=1></el-option>
              <el-option label="无缴费" value=0></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="缴费时间" :label-width="formLabelWidth">
            <el-input v-model="car.chargeDate" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="到期时间" :label-width="formLabelWidth">
            <el-input v-model="car.arrivedDate" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="缴费金额" :label-width="formLabelWidth">
            <el-input v-model="car.money" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="备注" :label-width="formLabelWidth">
            <el-input v-model="car.remark" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item :label-width="formLabelWidth" style="width:350px;display:block;margin: 0 auto">
            <el-button @click="dialogFormVisible1 = false">取 消</el-button>
            <el-button type="primary" @click="handleEdit()">确 定</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    </el-main>
  </el-container>

  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      formInline: {
        carId: '',
        chargeState: ''
      },
      carChargeArr:[],
      dialogFormVisible:false,
      dialogFormVisible1:false,
      formLabelWidth:'120px',
      car:{
        id:'',
        carId:'',
        chargePerson:'',
        chargeDate:'',
        chargeState:'',
        arrivedDate:'',
        money:'',
        remark:''
      },
      multipleSelection:[]
    }
  },
  created: function() {
    this.searchCar()
    this.axios.post("http://localhost:8080/parking/count/select").then((response) =>{
      this.count=response.data
    })
},
  methods: {
    reFresh(){
      this.searchCar();
    },
    handleEdit(){
      this.dialogFormVisible1 = false
      this.$message.success("缴费成功")
      this.axios.post("http://localhost:8080/parking/edit/update", this.car).then((response) => {
        this.searchCar();
      })
    },
    add(){
      this.dialogFormVisible = false
      this.$message.success("添加用户成功")
      this.axios.post("http://localhost:8080/parking/add/insert", this.car).then((response) => {
        this.searchCar();
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    searchCar(){
      this.axios.post("http://localhost:8080/parking/search/select").then((response)=>{
        this.carChargeArr = response.data
      })
    },
    deleteRow(index,row){
      this.axios.post("http://localhost:8080/parking/user/delete", row).then((response) => {
          this.$message.success("删除用户成功")
        this.searchCar();
      })
    },
    deletes(){
      this.axios.post("http://localhost:8080/parking/users/delete", this.multipleSelection).then((response) => {
          this.$message.success("删除用户成功")
        this.searchCar();
      })
    },
    onSubmit() {
        axios.post("http://localhost:8080/parking/select",this.formInline)
            .then((response)=>{
              this.carChargeArr=response.data;
            })
    },
    Submit(){
      axios.post("http://localhost:8080/parking/selects",this.formInline)
          .then((response)=>{
            this.carChargeArr=response.data;
          })
    },
  }
}
</script>